package com.lepu.flutterdemo.boost;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.lepu.flutterdemo.R;

/**
 * @author yangqing
 * @time 2021/10/11 17:14
 * @describe
 */
public class NativePageActivity extends AppCompatActivity {

    private TextView tvReciveParams;
    private Button btnClose;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_native_page);
        tvReciveParams = findViewById(R.id.tvReciveParams);
        btnClose = findViewById(R.id.btnClose);
        String param = getIntent().getStringExtra("param");
        tvReciveParams.setText(param);
        btnClose.setOnClickListener(v -> {
            closeAndReturnResult();
        });
    }

    public void closeAndReturnResult() {
        Intent intent = new Intent();
        intent.putExtra("msg","This message is from Native!!!");
        intent.putExtra("bool", true);
        intent.putExtra("int", 666);
        setResult(Activity.RESULT_OK, intent);  // 返回结果给dart
        super.finish();
    }
}
